import axios from '@/utils/request'

// 获取评论列表
/**
 *
 * @param {*} source 文章的源id
 * @param {*} offset 获取评论一句的偏移量,值为评论id
 * @returns
 */
export function getCommentList(source, offset) {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source,
      offset,
      limit: 10
    }
  })
}

// 获取评论回复数据

/**
 *
 * @param {*} source 评论id
 * @param {*} offset 获取评论数据的偏移量,值为评论id
 * @returns
 */
export function getCommentReply(source, offset) {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source,
      offset,
      limit: 10
    }
  })
}

// 发表评论

/**
 *
 * @param {*} target 文章id
 * @param {*} content 评论内容
 * @returns
 */
export function publishComment(target, content) {
  return axios({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      target,
      content
    }
  })
}

// 发表回复评论

/**
 *
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @param {*} artId 文章id
 * @returns
 */
export function addReply(target, content, artId) {
  return axios({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      target,
      content,
      art_id: artId
    }
  })
}

// 评论点赞

/**
 *
 * @param {*} target 点赞的评论id
 * @returns
 */
export function likeComment(target) {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'post',
    data: {
      target
    }
  })
}

// 取消点赞

/**
 *
 * @param {*} target 取消点赞的评论的id
 * @returns
 */
export function cancelLikeComment(target) {
  return axios({
    url: `/v1_0/comment/likings/${target}`,
    method: 'delete'
  })
}
